home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / prim / gui.el.z / gui.el
Encoding:
Text File  |  1998-05-21  |  4.2 KB  |  112 lines

  1. ;;; gui.el --- Basic GUI functions for XEmacs.
  2.  
  3. ;; Copyright (C) 1996 Ben Wing
  4.  
  5. ;; Maintainer: XEmacs Development Team
  6. ;; Keywords: internal
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  22. ;; Free Software Foundation, 59 Temple Place - Suite 330,
  23. ;; Boston, MA 02111-1307, USA.
  24.  
  25. (defcustom dialog-frame-plist '(width 60 height 20)
  26.   "Plist of frame properties for initially creating a dialog frame.
  27. Properties specified here supersede the values given in
  28. `default-frame-plist'."
  29.   :type '(repeat (group :inline t
  30.             (symbol :tag "Property")
  31.             (sexp :tag "Value")))
  32.   :group 'frames)
  33.  
  34. (defun make-dialog-frame (&optional props parent)
  35.   "Create a frame suitable for use as a dialog box.
  36. The frame is made a child of PARENT (defaults to the selected frame),
  37. and has additional properties PROPS, as well as `dialog-frame-plist'.
  38. Normally it also has no modelines, menubars, or toolbars."
  39.   (or parent (setq parent (selected-frame)))
  40.   (let* ((ftop (frame-property parent 'top))
  41.      (fleft (frame-property parent 'left))
  42.      (fwidth (frame-pixel-width parent))
  43.      (fheight (frame-pixel-height parent))
  44.      (fonth (font-height (face-font 'default)))
  45.      (fontw (font-width (face-font 'default)))
  46.      (props (append props dialog-frame-plist))
  47.      (dfheight (plist-get props 'height))
  48.      (dfwidth (plist-get props 'width))
  49.      ;; under FVWM at least, if I don't specify the initial position,
  50.      ;; it ends up always at (0, 0).  xwininfo doesn't tell me
  51.      ;; that there are any program-specified position hints, so
  52.      ;; it must be an FVWM bug.  So just be smashing and position
  53.      ;; in the center of the selected frame.
  54.      (frame (make-frame
  55.          (append props
  56.              `(popup ,parent initially-unmapped t
  57.                  menubar-visible-p nil
  58.                  has-modeline-p nil
  59.                  default-toolbar-visible-p nil
  60.                  modeline-shadow-thickness 0
  61.                  left ,(+ fleft (- (/ fwidth 2)
  62.                            (/ (* dfwidth fontw)
  63.                               2)))
  64.                  top ,(+ ftop (- (/ fheight 2)
  65.                          (/ (* dfheight fonth)
  66.                             2))))))))
  67.     (set-face-foreground 'modeline [default foreground] frame)
  68.     (set-face-background 'modeline [default background] frame)
  69.     (make-frame-visible frame)
  70.     frame))
  71.  
  72. (defvar gui-button-shadow-thickness 2)
  73.  
  74. (defun gui-button-p (object)
  75.   "True if OBJECT is a GUI button."
  76.   (and (vectorp object)
  77.        (> (length object) 0)
  78.        (eq 'gui-button (aref object 0))))
  79.  
  80. (make-face 'gui-button-face "Face used for gui buttons")
  81. (if (not (face-differs-from-default-p 'gui-button-face))
  82.     (progn
  83.       (set-face-reverse-p 'gui-button-face t)
  84.       (set-face-background 'gui-button-face "grey75" nil '(x color))
  85.       (set-face-foreground 'gui-button-face "black" nil '(x color))))
  86.  
  87. (defun make-gui-button (string &optional action user-data)
  88.   "Make a GUI button whose label is STRING and whose action is ACTION.
  89. If the button is inserted in a buffer and then clicked on, and ACTION
  90. is non-nil, ACTION will be called with one argument, USER-DATA."
  91.   (vector 'gui-button
  92.       (if (featurep 'xpm)
  93.           (xpm-button-create
  94.            string gui-button-shadow-thickness
  95.            (color-instance-name (face-foreground-instance 'gui-button-face))
  96.            (color-instance-name (face-background-instance 'gui-button-face)))
  97.         (xbm-button-create string gui-button-shadow-thickness))
  98.       action user-data))
  99.  
  100. (defun insert-gui-button (button &optional pos buffer)
  101.   "Insert GUI button BUTTON at POS in BUFFER."
  102.   (check-argument-type 'gui-button-p button)
  103.   (let ((annotation
  104.      (make-annotation (make-glyph (car (aref button 1)))
  105.               pos 'text buffer nil
  106.               (make-glyph (cadr (aref button 1)))))
  107.     (action (aref button 2)))
  108.     (and action
  109.      (progn
  110.        (set-annotation-action annotation action)
  111.        (set-annotation-data annotation (aref button 3))))))
  112.